<?php
class Package {
	private static $package = null;
	private static $cfg = array();
	
	public static function setCfg($cfg = array()) {
		self::$cfg = require FRAMEWORK_PACKAGE_ROOT . 'config.php';
		
		foreach($cfg as $key => $val) {
			if(array_key_exists($key, self::$cfg)) self::$cfg[$key] = $val;
		}
	}
	
	public static function getCfg($item = '') {
		$ret = null;
		
		if('' === $item) $ret = self::$cfg;
		elseif(array_key_exists($item, self::$cfg)) $ret = self::$cfg[$item];
		
		return $ret;
	}
	
	public static function compress($in = '', $cfg = array()) {
		self::initial($cfg);
		
		return self::$package->compress($in);
	}
	
	public static function uncompress($in = '', $cfg = array()) {
		self::initial($cfg);
		return self::$package->uncompress($in);
	}
	
	public function fcompress($in = null, $out = './', $cfg = array()) {
		self::initial($cfg);
		return self::$package->fcompress($in, $out);
	}
	
	public function funcompress($in = null, $out = './', $cfg = array()) {
		self::initial($cfg);
		return self::$package->funcompress($in, $out);
	}
	
	private static function initial($cfg = array()) {
		self::setCfg($cfg);
		
		$clz = ucfirst(strtolower(self::getCfg('type'))) . 'Package';
		$clzFile = FRAMEWORK_PACKAGE_ROOT . "drivers/{$clz}.class.php";
		
		if(file_exists($clzFile)) {
			require_once $clzFile;
			self::$package = new $clz();
		} else {
			FException::throwEx('type invalid');
		}
	}
}
?>